package end.TEST;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import end.bean.Album;
import end.bean.Announcement;
import end.bean.Chapter;
import end.bean.LogInfo;
import end.bean.shiro.Manager;
import end.bean.shiro.Role;
import end.dao.InitialDataDAO;
import end.ser.AlbumSER;
import end.ser.AnnouncementSER;
import end.ser.ChapterSER;
import end.ser.InitialDataSER;
import end.ser.LogInfoSER;
import end.ser.ManagerSER;
import end.ser.RoleSER;
import end.util.AESUtils;
import end.util.JsonUtil;
import end.util.export.excel.ExcelDto;
import end.util.export.excel.ExcelUtil;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/end/spring/cfg/applicationContext.xml")
@Transactional
public class SpringServiceTest {
	@Autowired
	private AlbumSER<Album> albumSER;
	@Autowired
	private ChapterSER<Chapter> chapterSER;

	public ChapterSER<Chapter> getChapterSER() {
		return chapterSER;
	}

	public void setChapterSER(ChapterSER<Chapter> chapterSER) {
		this.chapterSER = chapterSER;
	}

	public AlbumSER<Album> getAlbumSER() {
		return albumSER;
	}

	public void setAlbumSER(AlbumSER<Album> albumSER) {
		this.albumSER = albumSER;
	}

	@Autowired
	private RoleSER<Role> roleSER;

	public RoleSER<Role> getRoleSER() {
		return roleSER;
	}

	public void setRoleSER(RoleSER<Role> roleSER) {
		this.roleSER = roleSER;
	}

	@Autowired
	private ManagerSER<Manager> managerSER;

	public ManagerSER<Manager> getManagerSER() {
		return managerSER;
	}

	public void setManagerSER(ManagerSER<Manager> managerSER) {
		this.managerSER = managerSER;
	}

	@Autowired
	private LogInfoSER<LogInfo> logSER;

	public LogInfoSER<LogInfo> getLogSER() {
		return logSER;
	}

	public void setLogSER(LogInfoSER<LogInfo> logSER) {
		this.logSER = logSER;
	}

	@Autowired
	private InitialDataSER initialDataSER;

	public InitialDataSER getInitialDataSER() {
		return initialDataSER;
	}

	public void setInitialDataSER(InitialDataSER initialDataSER) {
		this.initialDataSER = initialDataSER;
	}

	@Autowired
	private AnnouncementSER<Announcement> announcementSER;

	public AnnouncementSER<Announcement> getAnnouncementSER() {
		return announcementSER;
	}

	public void setAnnouncementSER(AnnouncementSER<Announcement> announcementSER) {
		this.announcementSER = announcementSER;
	}

	@Test
	public void test1() {

		Integer[] rightsID = roleSER.queryRoleRightsByManager(1);
		System.out.println(("  该用户可使用的资源是    " + JsonUtil.toJson(rightsID)));
	}

	@Test
	public void test2() {
		Manager manger = new Manager();
		manger.setCode("hawk");
		manger.setId(3);
		System.out.println(("  该用户可使用的资源是    " + managerSER
				.isManagerCodeAlreadyUsed(manger)));
	}

	@Test
	public void test3() throws Exception {
		FileUtils.forceMkdir(new File("e:/" + "tempExcelDir"));
		// AESUtils.aesDecrypt("0000000000000000","proudToLoveAdios");
	}

	@Test
	public void test4() throws Exception {
		FileUtils
				.deleteDirectory(new File(
						"G:\\java资料\\开发工具\\apache-tomcat-7.0.61\\webapps\\thesisR\\tempExcelDir"));
	}

	@Test
	public void test5() throws Exception {
		Album album = new Album();
		album.getPageUtil().setPaging(true);
		album.getPageUtil().setOrderByCondition("score");
		album.getPageUtil().setQueryCondition("desc");
		album.getPageUtil().setPageOffset(0);
		album.getPageUtil().setPageSize(6);
		album.setUseStatus('0');
		List<Album> beans = albumSER.selectByBean(album);
		System.out.println(beans);
	}

	@Test
	public void test6() throws Exception {
		String sqlStr = "";
		InputStreamReader read = new InputStreamReader(new FileInputStream(
				new File("E:/init.sql")), "utf-8");// 考虑到编码格式
		String readLine = null;
		BufferedReader bufferedReader = new BufferedReader(read);
		while ((readLine = bufferedReader.readLine()) != null) {
			if (!readLine.startsWith("/*") || readLine.length() == 0) {
				sqlStr = sqlStr + readLine;
			}
		}
		bufferedReader.close();
		System.out.println(sqlStr);
		initialDataSER.initialMainData(sqlStr);
	}
	@Test
	public void test7() throws Exception {
		announcementSER.listAnnouncementByManager();
	}
}
